--[[--
类名: TencentLoginView.lua
创建日期: 2016-5-31
创建人: 陈小虎
功能描述: 公告
修改内容：
修改日期:   
修改人:     
修改备注: 
]]

local TencentLoginView = class("TencentLoginView",function() 
    return display.newTouchLayer()
end)


function TencentLoginView:ctor()
    self.mUINode=cc.CSLoader:createNode(Res.TencentLoginUI)
    display.doLayout(self.mUINode)
    self:addChild(self.mUINode)
    self:initView()
end

function TencentLoginView:initView()
    self._ui = display.uiDelegate(self.mUINode)

    self._ui.Button_o:addClickEventListener(function()
            self:_openConfirmView()
        end)
    self._ui.Button_w:addClickEventListener(function()
            executeFunc(self._onOperate, "wx", self)
        end)
    self._ui.Button_q:addClickEventListener(function()
            executeFunc(self._onOperate, "qq", self)
        end)

    local width = self._ui.Panel:getContentSize2()
    if app:isIOS() then
        if not app.channelAPI:isPlatformInstalled(Enums.MSDK_PLATFORM.WX) then
            self._ui.Button_o:setVisible(true)
            self._ui.Button_w:setVisible(false)
            self._ui.Button_o:setPositionX(width*0.35)
            self._ui.Button_q:setPositionX(width*0.65)
        else
            self._ui.Button_o:setVisible(true)
            self._ui.Button_w:setVisible(true)
            self._ui.Button_o:setPositionX(width*0.3)
            self._ui.Button_w:setPositionX(width*0.5)
            self._ui.Button_q:setPositionX(width*0.7)
        end
    else
        self._ui.Button_o:setVisible(false)
        self._ui.Button_w:setPositionX(width*0.35)
        self._ui.Button_q:setPositionX(width*0.65)
    end
end

function TencentLoginView:_openConfirmView()
    self:_closeConfirmView()

    local node = cc.CSLoader:createNode(Res.TencentLoginTipUI)
    display.doLayout(node)
    self:addChild(node)
    self._ui2 = display.uiDelegate(node)
    self._confirmNode = node

    -- 部分机器上文本显示不全，把size设置高一点
    local contentText = node:findChild("Panel/Panel_text/Text")
    local size = contentText:getContentSize()
    size.height = size.height + 20
    contentText:setContentSize(size)

    self._ui2.Button_o:addClickEventListener(function()
            self:_closeConfirmView()
            executeFunc(self._onOperate, "guest", self)
        end)
    self._ui2.Button_w:addClickEventListener(function()
            self:_closeConfirmView()
            executeFunc(self._onOperate, "wx", self)
        end)

    local width = self._ui2.Panel:getContentSize2()
    if app:isIOS()  and not app.channelAPI:isPlatformInstalled(Enums.MSDK_PLATFORM.WX) then
        self._ui2.Button_w:setVisible(false)
        self._ui2.Button_q:setPositionX(width*0.5)
    else
        self._ui2.Button_w:setVisible(true)
        self._ui2.Button_w:setPositionX(width*0.67)
        self._ui2.Button_q:setPositionX(width*0.33)
    end

    self._ui2.Button_q:addClickEventListener(function()
            self:_closeConfirmView()
            executeFunc(self._onOperate, "qq", self)
        end)
    self._ui2.Button_close:addClickEventListener(function()
            self:_closeConfirmView()
        end)
end

function TencentLoginView:_closeConfirmView()
    if self._confirmNode then
        self._confirmNode:removeFromParent()
        self._confirmNode = nil
    end
end

function TencentLoginView:enableButtons(b)
    display.setBtnTouchEnable(self._ui.Button_o, b)
    if not b then
        self._ui.Button_o:performWithDelay(function()
                display.setBtnTouchEnable(self._ui.Button_o, true)
            end, 3)
    else
        self._ui.Button_o:stopAllActions()
    end

    display.setBtnTouchEnable(self._ui.Button_w, b)
    if not b then
        self._ui.Button_w:performWithDelay(function()
                display.setBtnTouchEnable(self._ui.Button_w, true)
            end, 3)
    else
        self._ui.Button_w:stopAllActions()
    end

    display.setBtnTouchEnable(self._ui.Button_q, b)
    if not b then
        self._ui.Button_q:performWithDelay(function()
                display.setBtnTouchEnable(self._ui.Button_q, true)
            end, 3)
    else
        self._ui.Button_q:stopAllActions()
    end
end

function TencentLoginView:onOperate(cb)
    self._onOperate = cb
end


return TencentLoginView